/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.zbxsoft.uct.util  
 */
package com.apache.bid.common;

import java.io.UnsupportedEncodingException;

import com.apache.uct.common.ToolsUtil;

/**
 * description:  
 * @author  创建时间：2015-3-10  
 * 
 */
public class WbdStringUtil {

	/**
	 * 属性值生成,符合骆驼命名
	 * @param str
	 * @return
	 */
	public static String toCamelNamed(String str) {
		if (ToolsUtil.isNull(str))
			return "";
		String names[] = str.split("_");
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < names.length; i++) {
			if (i == 0) {
				sb.append(names[i].toLowerCase());
			} else {
				sb.append(names[i].substring(0, 1).toUpperCase() + names[i].substring(1).toLowerCase());
			}
		}
		return sb.toString();
	}

	/**
	 * description:  返回用户类型
	 * @param sysEname 
	 * @param delStatus
	 */
	public static String getSysFlag(String sysEname, String delStatus) {
		if (ToolsUtil.isNull(sysEname) && ("F".equals(delStatus) || "T".equals(delStatus)))
			return "0";
		else if ("1".equals(sysEname) && ("F".equals(delStatus) || "T".equals(delStatus)))
			return "1";
		else if ("0".equals(sysEname) && ("F".equals(delStatus) || "T".equals(delStatus))) {
			return "0";
		} else
			return delStatus;
	}
	/**
	 * 返回中文乱码转换成UTF-8格式
	 * @param str
	 * @return
	 */
	public static String getChUTF8(String str){
		String value = str;
		if (!ToolsUtil.isNull(value)) {
			try {
				if (value.equals(new String(value.getBytes("iso8859-1"), "iso8859-1"))) {
					value = new String(value.getBytes("iso8859-1"), "utf-8");
				}
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return value;
	}
}
